package com.yunduo.aspect;

import com.yunduo.common.JwtUtils;
import com.yunduo.common.RetunData.CommonReturn;
import com.yunduo.common.RetunData.statuscode.impl.FileCode;
import com.yunduo.common.RetunData.statuscode.impl.ResultCode;
import com.yunduo.common.YunDuoUtils;
import com.yunduo.entity.Good;
import com.yunduo.entity.User;
import com.yunduo.module.task.DeleteFileTask;
import com.yunduo.service.PFileService;
import com.yunduo.service.ShopService;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
@Aspect
@Component
@Slf4j
public class ShopAspect {
    @Resource
    private ShopService shopService;
    @Resource
    private PFileService pFileService;
    //删除店铺的切面
    @Pointcut(value = "execution(* com.yunduo.controller.ShopController.deleteShops(..))")
    public void deletePoint(){}

    //切面删除商店剩余数据
    @Before(value = "ShopAspect.deletePoint()")
    public void loginUserTotal(JoinPoint point) {
        Object arg0 = point.getArgs()[0];
        String[] ids = (String[])arg0;
        DeleteFileTask deleteFileTask = new DeleteFileTask(pFileService, shopService, ids);
        User user = JwtUtils.getDataByJwtToken(YunDuoUtils.getRequest());
        StringBuilder shopIds = new StringBuilder();
        for(int i = 0; i < ids.length; i++){
            shopIds.append(ids[i]+" ");
        }
        log.info(user.getName() + " " + "删除店铺:"+shopIds+" 附带资源");
        deleteFileTask.start();
    }
}
